#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<errno.h>
#include<sys/wait.h>
#include<sys/types.h>

int main()
{
    printf("%d\n",getpid());
    pid_t pid = fork();
    if(pid == -1)
    {
        perror("fork");
        exit(1);
    }

    if(pid == 0)
    {
        sleep(20);
        exit(10);
    }
    else 
    {
        int st;
        int ret = wait(&st);

        if(ret > 0 && (st&0X7F ) == 0)
        {
            // 正常退出
            printf("child exit code: %d\n", (st>>8)&0XFF);
        }
        else if(ret > 0)
        {
            printf("sig code: %d\n", st&0X7F);
        }
    }
    
    
    return 0;
}
